/***********************************************
 @Name :        小谭老师
 @Time :        2025-2-22
 @Email :       tan.zhipeng@outlook.com
 @Comment :     功能窗口 天气预报
 @FileName :    widget_assist_smart_weather.h
 @Version :     1.0
************************************************/

#ifndef WIDGET_FUNCD_WEATHER_H
#define WIDGET_FUNCD_WEATHER_H

#include <QWidget>
#include <QLineEdit>
#include <QPushButton>
#include <QLabel>
#include <QHBoxLayout>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QJsonParseError>
#include <QVector>
#include <QListView>
#include <QTimer>
#include <QStandardItemModel>
#include <qdesktopwidget.h>
#include "weatherdata.h"
#include "weatherdisplaybox.h"
#include "currweatherbox.h"
#include "temperaturechart.h"
#include "citydao.h"

namespace Ui {
class Widget_funcD_Weather;
}

class Widget_funcD_Weather : public QWidget
{
    Q_OBJECT
    
public:
    explicit Widget_funcD_Weather(QWidget *parent = nullptr);
    ~Widget_funcD_Weather();
    // 浮动子窗口显示列表
    QWidget *resultPopup;
    void positionResultPopup();
protected:
    void searchButtonClick();
    void searchInputTextChange(const QString &text);
    void onWeatherReplyFinished(QNetworkReply* reply);
    QString extractNumber(const QString& input);
    void onResultViewClicked(const QModelIndex &index);
    
    // 窗口大小变化时需要重新定位
    void resizeEvent(QResizeEvent *event);
private:
    Ui::Widget_funcD_Weather *ui;
    
    QLineEdit *searchInput;
    // 结果显示列表
    QListView *resultView;
    QStandardItemModel *model;
    QPushButton *searchButton;
    
    // 搜索框模糊查询的数据
    QList<City> *searchInputDataList;
    
    QLabel *city_label;
    QNetworkAccessManager *manager;
    
    CurrWeatherBox *curr_weather_box1;
    CurrWeatherBox *curr_weather_box2;
    CurrWeatherBox *curr_weather_box3;
    
    WeatherDisplayBox *weatherBox_1;
    WeatherDisplayBox *weatherBox_2;
    WeatherDisplayBox *weatherBox_3;
    WeatherDisplayBox *weatherBox_4;
    WeatherDisplayBox *weatherBox_5;
    WeatherDisplayBox *weatherBox_6;
    WeatherDisplayBox *weatherBox_7;
    QVector<WeatherDisplayBox*> box_arr;
    
    TemperatureChart *m_tempChart;  // 手绘折线图对象
    
    CityDao *cityDao;
    
};

#endif // WIDGET_FUNCD_WEATHER_H
